<template>
  <div class="user-edit">
    <!-- Modal -->
    <Modal
      :title="title"
      v-model="visible"
      width="620"
      :loading="visible"
      :mask-closable="type == '0'"
    >
      <div :style="{ maxHeight: maxHeight }" class="drawer-content">
        <Form
          ref="form"
          :model="form"
          :rules="ruleValidate"
          label-position="top"
        >
          <Row :gutter="32">
            <Col span="12">
              <FormItem label="昵称：" prop="nickname">
                <Input v-model="form.nickname" placeholder="请填写昵称" />
              </FormItem>
            </Col>
            <Col span="12">
              <FormItem label="真实姓名：" prop="realName">
                <Input v-model="form.realName" placeholder="请填写真实姓名" />
              </FormItem>
            </Col>
          </Row>
          <Row :gutter="32">
            <Col span="12">
              <FormItem label="手机号：" prop="mobile">
                <Input v-model="form.mobile" placeholder="请填写手机号" />
              </FormItem>
            </Col>
            <Col span="12">
              <FormItem label="身份证号：" prop="idCard">
                <Input v-model="form.idCard" placeholder="请填写身份证号" />
              </FormItem>
            </Col>
          </Row>
          <!-- <Row :gutter="32">
            <Col span="12"> 
              <Button type="primary" :loading="submitLoading" @click="submit">保存</Button>
              <Button @click="visible = false">取消</Button>
            </Col>
          </Row> -->
        </Form>
      </div>
      <div slot="footer">
        <Button type="primary" :loading="submitLoading" size="large" @click="submit">保存</Button>
        <Button size="large" @click="cancel">取消</Button>
      </div>
    </Modal>
  </div>
</template>
<script>
import { scUserAdd } from "@/api/index";
export default {
  name: "user",
  components: {
  },
  props: {
    value: {
      type: Boolean,
      default: false,
    },
    data: {
      type: Object,
    },
    type: {
      type: String,
      default: "0",
    },
    companyId: {
      type: String,
    }
  },
  data() {
    return {
      visible: this.value,
      title: "添加",
      passColor: "",
      submitLoading: false,
      maxHeight: 510,
      companyNatureList: [], //企业性质列表
      form: {
        
      },
      ruleValidate: {
        nickname: [
          { required: true, message: "请输入昵称", trigger: "blur" }
        ],
        realName: [
          { required: true, message: "请输入真实姓名", trigger: "blur" }
        ],
        mobile: [
          { required: true, message: "请输入手机号", trigger: "blur" }
        ],
        idCard: [
          { required: true, message: "请输入身份证号", trigger: "blur" }
        ],
      },
      
    };
  },
  methods: {
    cancel() {
      this.visible = false
    },
    submit() {
      this.$refs.form.validate((valid) => {
        if(valid) {
          this.form.companyId = this.companyId
          scUserAdd(this.form).then(res => {
            if (res.success) {
              this.$Message.success("操作成功")
              this.visible = false
              this.$emit("on-submit", true);
            }
          })
        }
      });
    },
    setCurrentValue(value) {
      if (value === this.visible) {
        return;
      }
      this.visible = value;
    },
    // getFindAllData() {
    //   getFindAll().then(res => {
    //     if (res.success) {
    //       this.companyNatureList = res.result;
    //     }
    //   })
    // },
  },
  watch: {
    value(val) {
      this.setCurrentValue(val);
    },
    visible(value) {
      this.$emit("input", value);
    },
  },
  mounted() {
    // this.getFindAllData()
  }
};
</script>

<style lang="less">
@import "@/styles/drawer-common.less";
</style>

